<!-- 组织机构管理 -->
<div class="easyui-layout">
    <div style="margin:20px;">
        {#股票基础数据#}

        <div id="stockinfo_toolbar" style="padding:5px">
            <form action="" id="stockinfo_form">
                市场:
                <select class="easyui-combobox" panelHeight="auto" style="width:100px">
                    <option value="sh">沪A</option>
                    <option value="sz">深A股</option>
                    <option value="" selected="selected">沪深A</option>
                </select>
                行业:
                <input id="industySelectBox" class="easyui-combobox" name="industry_name"
                       data-options="valueField:'value',textField:'name',url:'/board/industry-info'" value=''/>
                股票首字母缩写:
                <input class="easyui-textbox" name="abridge"/>
                股票名称:
                <input class="easyui-textbox" name="stock_name"/>

                <a href="#" id="stockinfo_search">Search</a>

            </form>
            <button class="easyui-linkbutton" onclick="getStockFundsBatch()">批量获取股票资金</button>
            <button class="easyui-linkbutton" onclick="removeStock()">批量删除</button>
            <button class="easyui-linkbutton" onclick="getStockInfoByIndustry()">获取股票基础信息</button>
            <button class="easyui-linkbutton" onclick="$('#w').window('open')">新增股票信息</button>

            {#弹窗#}
            <div id="w" class="easyui-window" title="Modal Window"
                 data-options="modal:true,closed:true,iconCls:'icon-save'"
                 style="width:500px;height:200px;padding:10px;">
                <form id="ff" method="post" action="/save-stock_info">
                    <table cellpadding="5">
                        <tr>
                            <td>股票详情url:</td>
                            <td><input class="easyui-textbox" type="url" name="stock_detail_url"
                                       data-options="required:true"></input></td>
                        </tr>
                        <tr><input type="submit" class="easyui-linkbutton" value="提交"/></tr>
                    </table>
                </form>
                </form>
            </div>
        </div>
        <div id="stockinfo_sigle_day">
        </div>
    </div>

</div>

<script type="text/javascript">


    function removeStock() {
        var checkedItems = $('#stockinfo_sigle_day').datagrid('getChecked');
        if (listIsEmpty(checkedItems)) {
            $.messager.alert("操作提示", "请选中股票后操作！", "warning");
            return;
        }
        var names = [];
        $.each(checkedItems, function (index, item) {
            names.push(item.id);
        });
        $.ajax({
            /*type = "get",*/
            url: '/remove-stock-batch',
            dateType: "JSON",
            data: {"ids": names.join(',')},
            success: function (data, textStatus, jqXHR) {
                stockinfo.search();
            }
        });
    }


    function removeStock(stock) {

        $.ajax({
            /*type = "get",*/
            url: '/remove-stock-batch',
            dateType: "JSON",
            data: {"ids": stock},
            success: function (data, textStatus, jqXHR) {
                stockinfo.search();
            }
        });
    }


    function getStockInfoByIndustry() {
        $.ajax({
            /*type = "get",*/
            url: '/stock_info',
            dateType: "JSON",
            data: {"industry_name": $('#industySelectBox').val()},
            success: function (data, textStatus, jqXHR) {
                $.messager.show({
                    title: '提示',
                    msg: data,
                    showType: 'fade',      //设置显示类型
                    style: {left: 500, top: 100},     //设置弹框的位置
                    width: 100,                           //设置弹框的宽度和高度
                    height: 200,
                    timeout: 1000      //设置停留时间，1000毫秒
                });
                stockinfo.search();
            }
        });
    }


    function getStockFundsBatch() {
        var checkedItems = $('#stockinfo_sigle_day').datagrid('getChecked');
        if (listIsEmpty(checkedItems)) {
            $.messager.alert("操作提示", "请选中股票后操作！", "warning");
            return;
        }
        var names = [];
        $.each(checkedItems, function (index, item) {
            names.push(item.stock_code);
        });
        $.ajax({
            /*type = "get",*/
            url: '/stock_funds_batch',
            dateType: "JSON",
            data: {"stock_code": names.join(',')},
            success: function (data, textStatus, jqXHR) {
                $.messager.show({
                    title: '提示',
                    msg: data,
                    showType: 'fade',      //设置显示类型
                    style: {left: 500, top: 100},     //设置弹框的位置
                    width: 100,                           //设置弹框的宽度和高度
                    height: 200,
                    timeout: 1000      //设置停留时间，1000毫秒
                });
            }
        });
    }

    function listIsEmpty(list) {
        if (list == null || list.length == 0) {
            return true;
        }
        return false;
    }


    var stockinfo = {                     //obj对象
        search: function () {
            $('#stockinfo_sigle_day').datagrid('load', $("#stockinfo_form").parseForm());
        }
    };


    $('#stockinfo_sigle_day').datagrid({
        // width: 1500,                 //设置宽度
        url: '/board/stock-info',       //远程加载数据地址
        title: '股票数据',           //面板属性，添加标题
        iconCls: 'icon-search',     //添加图标
        method: 'get',
        queryParams: $("#stockinfo_form").parseForm(),
        selectOnCheck: true,
        columns: [[                 //设置要显示表格数据
            {
                field: 'id',
                // title: '股票名称',
                checkbox: true,
                width: 60
            },
            {
                field: 'stock_name',
                title: '股票名称',
                resizable: true,
                width: 60
            },
            {
                field: 'stock_code',
                title: '股票编码',
                resizable: true,
                width: 60
            },
            {
                field: 'market',
                title: '市场',
                resizable: true,
                width: 60
            }
            , {
                field: 'abridge',
                title: '拼音',
                resizable: true,
                width: 60
            }
            , {
                field: 'industry_name',
                title: '行业名称',
                resizable: true,
                width: 60
            }
            /* , {
                 field: 'concept',
                 title: '概念'
                 , width: 60
             }*/
            , {
                title: '操作',
                // resizable: true,
                field: '获取最新数据大厦的方式',
                width: 60,
                formatter: formatOper
            }

        ]],
        pagination: true,         //组件底部显示分页工具栏
        pageNumber: 1,             //设置分页时初始化页码
        pageSize: 20,               //设置分页时设置每页多少条
        pageList: [20, 50, 100],          //设置可选每页显示条数
        fitColumns: true,         //设置表格自适应
        {#scrollbarSize: 0,          //滚动条所占的宽度或高度。默认为18。#}
        rownumbers: true,
        toolbar: '#stockinfo_toolbar'           //引入id为tb的区块工具栏
    });

    $('#stockinfo_search').linkbutton({  //查询按钮
        iconCls: "icon-search"
    });
    //查询功能
    $('#stockinfo_search').click(function () {   //点击查询后执行obj对象里的search方法
        stockinfo.search();
    });

    function formatOper(val, row, index) {
        return '<a href="' + row.stock_detail_url + '" target="_blank">查看详情</a> ' +
            ' <a href="javascript:void(0);" onclick="removeStock(' + row.id + ')">删除</a>'
        // return '<a href="javascript:void(0);" onclick="importDateByNow(' + row.stock_code + ')">获取最新数据</a>'
    }

</script>

<script type="text/javascript" src="/web/static/js/index.js"></script>
